const Koa = require('koa')
const app = new Koa()
const koaBody = require('koa-body')
const router = require('../router/index')
app.use(koaBody())
app.use(router.routes()).use(router.allowedMethods());
app.on('error',(err,ctx) =>{
    let status = 500
    switch(err.code){
        case '10001':
            status = 400
            break
        case '10002':
            status = 409
            break

        default :
            status = 500
    }
    ctx.status = status
    ctx.body = err
})
module.exports = app
